import  request from "../utils/itemRequest";
import sphRequest from "../utils/http"
export interface categoryListData {
    categoryGroupList: categoryGroupData[];
    categoryL1List: categoryData[];
    categoryL2List: categoryData[];
    currentCategory: categoryData;
  }
  
  interface categoryGroupData {
      categoryList: categoryData[]
      id: number
      name: string
  }
  
  interface bannerListData {
      extra: {
          crmUserGroupId: string
          crmUserGroupName?: string
          itemFrom: number
          materialContentFrom: number
          materialId: string
          materialName: string
          materialType: string
          rcmdSort: boolean
          resourcesId: number
          taskId: string
          taskType: number
      }
      id: number
      picUrl: string
      targetUrl: string
  }
  export interface categoryData {
      bannerList:bannerListData[];
      bannerUrl: string;
      categoryType: number;
      extra: {
        crmUserGroupId: string;
        crmUserGroupName: string;
        itemFrom: number;
        materialContentFrom: number;
        materialId: string;
        materialName: string;
        materialType: string;
        rcmdSort: boolean;
        resourcesId: number;
        taskId: string;
        taskType: number;
      };
      frontDesc?: string;
      frontName?: string;
      frontNameIcon?: string;
      iconUrl?: string;
      id: number;
      imgUrl?: string;
      level?: string;
      name: string;
      showIndex: number;
      subCateList?: any;
      superCategoryId: number;
      type: number;
      wapBannerUrl: string;
      wapExpandPicTargetUrl?: string;
    }
  

//获取分类数据
export default {
    getCategoryList(categoryId?:number){
       return request.get<any,categoryListData>( '/cateList.json',{
        params:{
            categoryId
          }
       })
    }
}
export interface SpuSaleAttrValueListData {
    id: number
    spuId: number
    baseSaleAttrId: number
    saleAttrValueName: string
    saleAttrName: string
    isChecked: string
  }
  export type SpuSaleAttrListData = {
    id: number
    spuId: number
    baseSaleAttrId: number
    saleAttrName: string
    spuSaleAttrValueList: SpuSaleAttrValueListData[]
  }
  export interface CategoryViewData {
    id: number
    category1Id: number
    category1Name: string
    category2Id: number
    category2Name: string
    category3Id: number
    category3Name: string
  }
  
  export interface SkuImageData {
    id: number
    skuId: number
    imgName: string
    imgUrl: string
    spuImgId: number
    isDefault: string
  }
  
  export type SkuImageListData = SkuImageData[]
  
  export interface SkuAttrValueListData {
    id: number
    attrId: number
    valueId: number
    skuId: number
  }
  
  export type SkuInfoData = {
    id: number
    spuId: number
    price: number
    skuName: string
    skuDesc: string
    weight: string
    tmId: number
    category3Id: number
    skuDefaultImg: string
    isSale: number
    skuImageList: SkuImageListData
    skuAttrValueList: SkuAttrValueListData[]
    skuSaleAttrValueList: null
  }
  
  export type CardDetail = {
    price: number
    categoryView: CategoryViewData
    spuSaleAttrList: SpuSaleAttrListData[]
    skuInfo: SkuInfoData
  }
  
  export const reqCardDetail = (skuId: number) => {
    return sphRequest.get<any, CardDetail>(`/api/item/${skuId}`)
  }
  
  export const reqAddCard = (skuId: string, skuNum: number) => {
    return sphRequest.post<any, null>(`/api/cart/addToCart/${skuId}/${skuNum}`)
  }